Cover TOC Chap Prev Chap Prev Fig Next Fig Next Chap

Chapter 31: Creating New Node Types

../ch31/31fig09.gif
Figure 31.9

A SpinGroup node type used to automatically spin a group of three boxes.

31fig09.wrl
Click on the image to view the VRML scene.

#VRML V2.0 utf8
# The VRML 2.0 Sourcebook
# Copyright (c) 1997
# Andrea L. Ames, David R. Nadeau, and John L. Moreland
PROTO SpinGroup [
    exposedField MFNode  children      [ ]
    exposedField SFTime  cycleInterval 1.0
    exposedField SFBool  loop          FALSE
    exposedField SFTime  startTime     0.0
    exposedField SFTime  stopTime      0.0
] {
    DEF SpinMe Transform {
        children      IS children
    },
    DEF Clock TimeSensor {
        cycleInterval IS cycleInterval
        loop          IS loop
        startTime     IS startTime
        stopTime      IS stopTime
    },
    DEF Spinner OrientationInterpolator {
        key [ 0.0, 0.5, 1.0 ]
        keyValue [
            0.0 1.0 0.0 0.0,
            0.0 1.0 0.0 3.14,
            0.0 1.0 0.0 6.28
        ]
    },
    ROUTE Clock.fraction_changed TO Spinner.set_fraction
    ROUTE Spinner.value_changed  TO SpinMe.set_rotation
}

SpinGroup {
    cycleInterval 4.0
    loop TRUE
    children [
        Shape {
            appearance DEF Green Appearance {
                material Material { diffuseColor 0.0 1.0 0.3 }
            }
            geometry Box { size 25.0 2.0 2.0 }
        },
        Shape {
            appearance USE Green
            geometry Box { size 2.0 25.0 2.0 }
        },
        Shape {
            appearance USE Green
            geometry Box { size 2.0 2.0 25.0 }
        }
    ]
}